<template>
    <div class="head">
        <div class="left" @click="goFrontHome">
            <img class="img" src="https://www.ptu.edu.cn/images/logo.png" alt="莆田学院标志">
        </div>
        <div class="right">
            <el-avatar class="avatar" :src="userInfoVo.avatar"> </el-avatar>
            <div class="dropdown">
                <a class="user">{{ userInfoVo.name }}
                    <i class="iconfont icon-xiangxia"></i>
                </a>
                <div class="user-message">
                    <router-link to="/personal">个人中心</router-link>
                    <a @click="logout">退出登录</a>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router'
import { getUserInfoAPI } from '@/api/api'


const router = useRouter()

const userInfoVo = ref({
    name: '请登录',
    avatar: '',
})

onMounted(() => {
    getUserInfo()
})

const getUserInfo = async () => {
    await getUserInfoAPI().then(res => {
        if (res.data.code == 200) {
            userInfoVo.value = res.data.data
            console.log(userInfoVo.value,'userInfoVo.value');
        }
    })
}

const goFrontHome = () => {
    router.push({
        name: 'frontHome'
    })
}
const logout = async () => {
    localStorage.clear()
    sessionStorage.clear()
    router.push({
        name: 'login'
    })
    // await logoutAPI().then(res => {
    //     if (res.data.code == 200) {
    //         router.push({
    //             name: 'login'
    //         })
    //         console.log(res.data.data);
    //     }
    // })
}

</script>

<style lang="less" scoped>
.head {
    display: flex;
    justify-content: space-between;
    padding: 0;
    border-bottom: 1px solid rgb(243, 242, 242);
    background: rgb(255, 255, 255);
    background: linear-gradient(0deg, rgba(255, 255, 255, 1) 0%, rgba(203, 222, 246, 1) 100%);
    position: fixed;
    min-width: 100vw;
    z-index: 100;

    .left {
        .img {
            width: 130px;
            overflow: hidden;
            color: #4a8de0;
            transform: translateY(-200px);
            filter: drop-shadow(0 200px);
            padding-left: 30px;
        }
    }

    .right {
        width: 20%;
        margin: auto 0;
        display: flex;
        justify-content: center;

        .avatar {
            margin: auto 0;
        }

        .dropdown {
            margin: auto 0;
            position: relative;
            display: inline-block;

            .user {
                margin-left: 10px;
                color: black;
                cursor: pointer;

                svg {
                    width: 10px;
                    height: 10px;
                    margin-left: 3px;
                }
            }

            .user:hover {
                color: rgb(83, 168, 255);
            }

            .user-message {
                display: none;
                position: absolute;
                background-color: #f9f9f9;
                min-width: 100px;
                border-radius: 10px;
                box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
                z-index: 200;
            }

            .user-message a {
                color: black;
                padding: 12px 16px;
                text-decoration: none;
                display: block;

            }
        }

        .dropdown:hover .user-message {
            display: block;

        }

        .user-message a:hover {
            background-color: rgb(217, 236, 255);
            color: rgb(83, 168, 255);
            border-radius: 10px;
        }
    }
}
</style>